package com.czl.base.util

import android.os.Bundle
import com.czl.base.base.BaseBean
import com.czl.base.base.BaseViewModel
import com.czl.base.extension.ApiSubscriberHelper

/**
 *
 * @Description:
 * @Author: XCH
 * @CreateDate: 2022/3/28 13:37
 */
object MessageHelper {

    fun navPage(jumpLink: String, viewModel: BaseViewModel<*>) {
        /**
         * /workOrderManage/complaintWorkOrder?id=TSJY20220310100030102913@&@/complaint/detail?work_order_no=TSJY20220310100030102913
         */
//        var jumpLink = "/workOrderManage/complaintWorkOrder?id=TSJY20220310100030102913@&@/report/detail?work_order_no=TSJY20220310100030102913"
        if (jumpLink.contains("@&@")) {
            var linkArr = jumpLink.split("@&@")
            if (linkArr.size == 2) {
                var appLink = linkArr.last()
                var routePath: String
                var paramMap = mutableMapOf<String, String>()
                if (appLink.contains("?")) {
                    var appLinkArr = appLink.split("?")
                    routePath = appLinkArr.first()
                    if (appLinkArr.size > 1) {
                        var paramStr = appLinkArr.last()
                        if (paramStr.contains("&")) {
                            var paramArr = paramStr.split("&")
                            paramArr.forEach {
                                var inn = it.split("=")
                                paramMap[inn[0]] = inn[1]
                            }
                        } else {
                            var inn = paramStr.split("=")
                            paramMap[inn[0]] = inn[1]
                        }
                    }
                } else {
                    routePath = linkArr[1]
                }
                if (paramMap.isNotEmpty()) {
                    viewModel.startContainerActivity(routePath, Bundle().apply {
                        paramMap.forEach {
                            putString(
                                it.key,
                                it.value
                            )
                        }

                    })
                } else {
                    viewModel.startContainerActivity(routePath)
                }
            }
        }
    }
}